package lablayer.model.MathComponents;

import java.util.HashMap;
import lablayer.model.LabData;

/**
 * @author Darkness
 */

class DotStudent implements MathComponent {
    private LabData result;

    private LabData data;

    private String componentName = "Критическая точка распределения Стьюдента";

    private String componentId = "3a";

    private HashMap<Integer, HashMap<Double, Double>> table;
    
    public DotStudent() {
        super();
        //initializing Student's table
        this.table = new HashMap<Integer, HashMap<Double, Double>>();

        //initializing rows of table
        HashMap<Double, Double> row = new HashMap<Double, Double>();
        //first row
        row.put(0.75, 1.0);
        row.put(0.875, 2.41);
        row.put(0.95, 6.31);
        row.put(0.975, 12.7);
        row.put(0.99, 31.82);
        row.put(0.995, 63.7);
        table.put(1, row);
        //second row
        row = new HashMap<Double, Double>();
        row.put(0.75, 0.816);
        row.put(0.875, 1.6);
        row.put(0.95, 2.92);
        row.put(0.975, 4.3);
        row.put(0.99, 6.97);
        row.put(0.995, 9.92);
        table.put(2, row);
        //and so on
        row = new HashMap<Double, Double>();
        row.put(0.75, 0.765);
        row.put(0.875, 1.42);
        row.put(0.95, 2.35);
        row.put(0.975, 3.18);
        row.put(0.99, 4.54);
        row.put(0.995, 5.84);
        table.put(3, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.741);
        row.put(0.875, 1.34);
        row.put(0.95, 2.13);
        row.put(0.975, 2.78);
        row.put(0.99, 3.75);
        row.put(0.995, 4.6);
        table.put(4, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.727);
        row.put(0.875, 1.3);
        row.put(0.95, 2.01);
        row.put(0.975, 2.57);
        row.put(0.99, 3.37);
        row.put(0.995, 4.03);
        table.put(5, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.718);
        row.put(0.875, 1.27);
        row.put(0.95, 1.94);
        row.put(0.975, 2.45);
        row.put(0.99, 3.14);
        row.put(0.995, 3.71);
        table.put(6, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.711);
        row.put(0.875, 1.25);
        row.put(0.95, 1.89);
        row.put(0.975, 2.36);
        row.put(0.99, 3.0);
        row.put(0.995, 3.5);
        table.put(7, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.706);
        row.put(0.875, 1.24);
        row.put(0.95, 1.86);
        row.put(0.975, 2.31);
        row.put(0.99, 2.9);
        row.put(0.995, 3.36);
        table.put(8, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.703);
        row.put(0.875, 1.23);
        row.put(0.95, 1.83);
        row.put(0.975, 2.26);
        row.put(0.99, 2.82);
        row.put(0.995, 3.25);
        table.put(9, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.7);
        row.put(0.875, 1.22);
        row.put(0.95, 1.81);
        row.put(0.975, 2.23);
        row.put(0.99, 2.76);
        row.put(0.995, 3.17);
        table.put(10, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.697);
        row.put(0.875, 1.21);
        row.put(0.95, 1.8);
        row.put(0.975, 2.2);
        row.put(0.99, 2.72);
        row.put(0.995, 3.11);
        table.put(11, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.695);
        row.put(0.875, 1.21);
        row.put(0.95, 1.78);
        row.put(0.975, 2.18);
        row.put(0.99, 2.68);
        row.put(0.995, 3.05);
        table.put(12, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.694);
        row.put(0.875, 1.2);
        row.put(0.95, 1.77);
        row.put(0.975, 2.16);
        row.put(0.99, 2.65);
        row.put(0.995, 3.01);
        table.put(13, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.692);
        row.put(0.875, 1.2);
        row.put(0.95, 1.76);
        row.put(0.975, 2.14);
        row.put(0.99, 2.62);
        row.put(0.995, 2.98);
        table.put(14, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.691);
        row.put(0.875, 1.2);
        row.put(0.95, 1.75);
        row.put(0.975, 2.13);
        row.put(0.99, 2.6);
        row.put(0.995, 2.95);
        table.put(15, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.69);
        row.put(0.875, 1.19);
        row.put(0.95, 1.75);
        row.put(0.975, 2.12);
        row.put(0.99, 2.58);
        row.put(0.995, 2.92);
        table.put(16, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.689);
        row.put(0.875, 1.19);
        row.put(0.95, 1.74);
        row.put(0.975, 2.11);
        row.put(0.99, 2.57);
        row.put(0.995, 2.9);
        table.put(17, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.688);
        row.put(0.875, 1.19);
        row.put(0.95, 1.73);
        row.put(0.975, 2.1);
        row.put(0.99, 2.55);
        row.put(0.995, 2.88);
        table.put(18, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.688);
        row.put(0.875, 1.19);
        row.put(0.95, 1.73);
        row.put(0.975, 2.09);
        row.put(0.99, 2.54);
        row.put(0.995, 2.86);
        table.put(19, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.687);
        row.put(0.875, 1.18);
        row.put(0.95, 1.73);
        row.put(0.975, 2.09);
        row.put(0.99, 2.53);
        row.put(0.995, 2.85);
        table.put(20, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.684);
        row.put(0.875, 1.18);
        row.put(0.95, 1.71);
        row.put(0.975, 2.06);
        row.put(0.99, 2.49);
        row.put(0.995, 2.79);
        table.put(25, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.683);
        row.put(0.875, 1.17);
        row.put(0.95, 1.7);
        row.put(0.975, 2.04);
        row.put(0.99, 2.46);
        row.put(0.995, 2.75);
        table.put(30, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.681);
        row.put(0.875, 1.17);
        row.put(0.95, 1.68);
        row.put(0.975, 2.02);
        row.put(0.99, 2.42);
        row.put(0.995, 2.7);
        table.put(40, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.679);
        row.put(0.875, 1.16);
        row.put(0.95, 1.67);
        row.put(0.975, 2.0);
        row.put(0.99, 2.39);
        row.put(0.995, 2.66);
        table.put(60, row);

        row = new HashMap<Double, Double>();
        row.put(0.75, 0.674);
        row.put(0.875, 1.15);
        row.put(0.95, 1.64);
        row.put(0.975, 1.96);
        row.put(0.99, 2.33);
        row.put(0.995, 2.58);
        table.put(61, row);
    }
   
    @Override
    public LabData getData() {
        return this.data;
    }

    @Override
    public void calculate() {
        Double[][][] data = this.data.getData();
        if (data.length != 0) {
            if (data[0].length != 0) {
                if (data[0][0].length >= 2) {
                    Double freedomDegrees = data[0][0][0];
                    Double signLevel = 1 - data[0][0][1];

                    if (freedomDegrees > 60) freedomDegrees = 61.0;
                    HashMap<Double, Double> row = this.table.get(freedomDegrees.intValue());
                    this.result = new LabData(row.get(signLevel));
                }
            }
        }
    }

    @Override
    public void setData(LabData data) {
        if (data != null) {
            this.data = data;
        } else {
            throw new UnsupportedOperationException();
        }
    }

    @Override
    public String getComponentId() {
        return this.componentId;
    }

    @Override
    public String getComponentName() {
        return this.componentName;
    }

    @Override
    public LabData getResult() {
        return this.result;
    }

	@Override
	public void setParameter(String params, String values) {
		throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public LabData getInitData() {
		throw new UnsupportedOperationException("Not supported yet.");
	}

}
